// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'
import qs from 'qs'
import JsonExcel from 'vue-json-excel'

/* 导出Excel */
Vue.component('downloadExcel', JsonExcel)
/* 设置axios的全局变量属性 */
Vue.prototype.$http = axios;
/* 设置qs的全局变量属性 */
Vue.prototype.$qs = qs;
/* 设置axios模块的域名代理地址 */
/* 前提是只有一个代理 */
axios.defaults.baseURL="/exam";

Vue.use(ElementUI);
Vue.config.productionTip = false


/* 定义导航钩子 */
/*
  to:要到达的路由对象
  from:从哪里来的路由对象
  next:用来定义要到达的路由地址
 */
router.beforeEach(function(to,from,next){
    //本地存储获取用户登录信息
    var name = sessionStorage.getItem("name");
    if(to.meta.isLogin){
      //放行
      next();
    }else{
     if(name == null){
       next("/");
     }else{
       next();
     }
    }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
